<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>numpy.savez_compressed &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../about.html" >
    <link rel="index" title="Index" href="../../genindex.html" >
    <link rel="search" title="Search" href="../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../index.html" >
    <link rel="up" title="Input and output" href="../routines.io.html" >
    <link rel="next" title="numpy.savetxt" href="numpy.savetxt.html" >
    <link rel="prev" title="numpy.savez" href="numpy.savez.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../index.html">
      <img border=0 alt="NumPy" src="../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../index.html" >NumPy Reference</a></li>
          <li class="active"><a href="../routines.html" >Routines</a></li>
          <li class="active"><a href="../routines.io.html" accesskey="U">Input and output</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="numpy.savetxt.html" title="numpy.savetxt"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="numpy.savez.html" title="numpy.savez"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="numpy.savez.html"
                        title="previous chapter">numpy.savez</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="numpy.savetxt.html"
                        title="next chapter">numpy.savetxt</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="numpy-savez-compressed">
<h1>numpy.savez_compressed<a class="headerlink" href="#numpy-savez-compressed" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="numpy.savez_compressed">
<code class="sig-prename descclassname">numpy.</code><code class="sig-name descname">savez_compressed</code><span class="sig-paren">(</span><em class="sig-param">file</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwds</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/numpy/numpy/blob/v1.18.1/numpy/lib/npyio.py#L655-L717"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numpy.savez_compressed" title="Permalink to this definition">¶</a></dt>
<dd><p>Save several arrays into a single file in compressed <code class="docutils literal notranslate"><span class="pre">.npz</span></code> format.</p>
<p>If keyword arguments are given, then filenames are taken from the keywords.
If arguments are passed in with no keywords, then stored filenames are
arr_0, arr_1, etc.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>file</strong><span class="classifier">str or file</span></dt><dd><p>Either the filename (string) or an open file (file-like object)
where the data will be saved. If file is a string or a Path, the
<code class="docutils literal notranslate"><span class="pre">.npz</span></code> extension will be appended to the filename if it is not
already there.</p>
</dd>
<dt><strong>args</strong><span class="classifier">Arguments, optional</span></dt><dd><p>Arrays to save to the file. Since it is not possible for Python to
know the names of the arrays outside <a class="reference internal" href="numpy.savez.html#numpy.savez" title="numpy.savez"><code class="xref py py-obj docutils literal notranslate"><span class="pre">savez</span></code></a>, the arrays will be saved
with names “arr_0”, “arr_1”, and so on. These arguments can be any
expression.</p>
</dd>
<dt><strong>kwds</strong><span class="classifier">Keyword arguments, optional</span></dt><dd><p>Arrays to save to the file. Arrays will be saved in the file with the
keyword names.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>None</strong></dt><dd></dd>
</dl>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="numpy.save.html#numpy.save" title="numpy.save"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.save</span></code></a></dt><dd><p>Save a single array to a binary file in NumPy format.</p>
</dd>
<dt><a class="reference internal" href="numpy.savetxt.html#numpy.savetxt" title="numpy.savetxt"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.savetxt</span></code></a></dt><dd><p>Save an array to a file as plain text.</p>
</dd>
<dt><a class="reference internal" href="numpy.savez.html#numpy.savez" title="numpy.savez"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.savez</span></code></a></dt><dd><p>Save several arrays into an uncompressed <code class="docutils literal notranslate"><span class="pre">.npz</span></code> file format</p>
</dd>
<dt><a class="reference internal" href="numpy.load.html#numpy.load" title="numpy.load"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.load</span></code></a></dt><dd><p>Load the files created by savez_compressed.</p>
</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>The <code class="docutils literal notranslate"><span class="pre">.npz</span></code> file format is a zipped archive of files named after the
variables they contain.  The archive is compressed with
<code class="docutils literal notranslate"><span class="pre">zipfile.ZIP_DEFLATED</span></code> and each file in the archive contains one variable
in <code class="docutils literal notranslate"><span class="pre">.npy</span></code> format. For a description of the <code class="docutils literal notranslate"><span class="pre">.npy</span></code> format, see 
<a class="reference internal" href="numpy.lib.format.html#module-numpy.lib.format" title="numpy.lib.format"><code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy.lib.format</span></code></a>.</p>
<p>When opening the saved <code class="docutils literal notranslate"><span class="pre">.npz</span></code> file with <a class="reference internal" href="numpy.load.html#numpy.load" title="numpy.load"><code class="xref py py-obj docutils literal notranslate"><span class="pre">load</span></code></a> a <em class="xref py py-obj">NpzFile</em> object is
returned. This is a dictionary-like object which can be queried for
its list of arrays (with the <code class="docutils literal notranslate"><span class="pre">.files</span></code> attribute), and for the arrays
themselves.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">test_array</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_vector</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">savez_compressed</span><span class="p">(</span><span class="s1">&#39;/tmp/123&#39;</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="n">test_array</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">test_vector</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">loaded</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s1">&#39;/tmp/123.npz&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array_equal</span><span class="p">(</span><span class="n">test_array</span><span class="p">,</span> <span class="n">loaded</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">]))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array_equal</span><span class="p">(</span><span class="n">test_vector</span><span class="p">,</span> <span class="n">loaded</span><span class="p">[</span><span class="s1">&#39;b&#39;</span><span class="p">]))</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>